home *** CD-ROM | disk | FTP | other *** search
/ Graphics Plus / Graphics Plus.iso / general / hdf / unix / examples.lha / examples / sds / slices / getslices.c next >
Encoding:
C/C++ Source or Header  |  1991-10-08  |  1.8 KB  |  81 lines

  1. /************************************************************ 
  2. *
  3. * Example program: Read in slices from a 10 x 12 SDS
  4. *
  5. * Input file:  named by user on command line
  6. * Output file: none (output is printed to the console)
  7. *
  8. ************************************************************ */
  9.  
  10. #include <stdio.h>
  11. #include "df.h"
  12. #define ROWS  10
  13. #define COLS  12
  14. #define TRUE   1
  15. #define FALSE  0
  16.  
  17. main(argc,argv)
  18. int argc;
  19. char *argv[];
  20. {
  21.     int  i, j, count, rank;
  22.     int dimsizes[2];
  23.     float data[ROWS][COLS];
  24.     
  25.     if (argc != 2) {
  26.         printf("Usage: %s infile\n", argv[0]);
  27.         exit(1);
  28.     }
  29.  
  30.     DFSDgetdims(argv[1], &rank, dimsizes, 3);
  31.  
  32. /**/printf("rank=%d, dimsizes=%d & %d\n",rank,dimsizes[0],dimsizes[1]);
  33.     /* read in two slices  */
  34.  
  35.     printf("\n\nReads in two slices from a scientific dataset.\n\n");
  36.     printf("First slice: 4x6 array starting at (3,4):\n");
  37.     getit(argv[1], 3,4,4,6, data, dimsizes);
  38.     printf("\n\nSecond slice: 10x2 array starting at (1,10):\n");
  39.     getit(argv[1], 1,10,10,2,data, dimsizes);
  40.     printf("\n");
  41.  
  42. }
  43.  
  44. getit(filename, st0, st1, rows, cols, data, dimsizes)
  45. int st0, st1, rows, cols, dimsizes[2];
  46. float *data;
  47. char *filename;
  48. {
  49.     int i, j, ret, winst[2], windims[2];
  50.  
  51.     winst[0]=st0; winst[1]=st1;
  52.     dimsizes[0] = windims[0] = rows; 
  53.     dimsizes[1] = windims[1] = cols;
  54. /**/printf("winst=%d & %d\nwindims=%d & %d\n",
  55.                                      winst[0],winst[1],windims[0],windims[1]);
  56.     ret = DFSDgetslice(filename, winst, windims, data, dimsizes);
  57.     if (ret != 0) {
  58.         printf("\nError calling DFSDgetslice.\n");
  59.         printf("ret = %d;  DFerror = %d\n\n", ret, DFerror);
  60.     }    
  61.  
  62.     for (i=0; i<rows; i++)  {
  63.         printf("\n  ");
  64.         for (j=0; j<cols; j++) {
  65.         printf("%5.0f%c",data[i*cols+j], ' ');
  66.         }
  67.     }
  68.     printf("\n\n");
  69. }
  70.  
  71.  
  72.  
  73.  
  74.  
  75.  
  76.  
  77.  
  78.  
  79.  
  80.  
  81.